﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Andrology : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        //DataView dvSqlAndrology = (DataView)SqlDataSource2.Select(DataSourceSelectArguments.Empty);
        /*foreach (DataRowView drvSqlAndrology in dvSqlAndrology)
        {
            Label1.Text = drvSqlAndrology["Title"].ToString();
            Image16.ImageUrl = "../Uploads/News/" + drvSqlAndrology["Thumb_Photo"].ToString();
            Image16.Width = 222;
            Image16.Height = 222;
        }*/
        /*DataRowView drvSqlAndrology0 = dvSqlAndrology[0];
        DataRowView drvSqlAndrology1 = dvSqlAndrology[1];
        DataRowView drvSqlAndrology2 = dvSqlAndrology[2];
        DataRowView drvSqlAndrology3 = dvSqlAndrology[3];
        DataRowView drvSqlAndrology4 = dvSqlAndrology[4];
        Label1.Text = drvSqlAndrology0["Title"].ToString();
        Label3.Text = drvSqlAndrology1["Title"].ToString();
        Label5.Text = drvSqlAndrology2["Title"].ToString();
        Label7.Text = drvSqlAndrology3["Title"].ToString();
        Label9.Text = drvSqlAndrology4["Title"].ToString();
        Label2.Text = drvSqlAndrology0["ShortDescription"].ToString();
        Label4.Text = drvSqlAndrology1["ShortDescription"].ToString();
        Label6.Text = drvSqlAndrology2["ShortDescription"].ToString();
        Label8.Text = drvSqlAndrology3["ShortDescription"].ToString();
        Label10.Text = drvSqlAndrology4["ShortDescription"].ToString();
        Image16.ImageUrl = "../Uploads/News/" + drvSqlAndrology0["Thumb_Photo"].ToString();
        Image16.Width = 240;
        Image16.Height = 160;
        Image17.ImageUrl = "../Uploads/News/" + drvSqlAndrology1["Thumb_Photo"].ToString();
        Image17.Width = 240;
        Image17.Height = 160;
        Image18.ImageUrl = "../Uploads/News/" + drvSqlAndrology2["Thumb_Photo"].ToString();
        Image18.Width = 240;
        Image18.Height = 160;
        Image19.ImageUrl = "../Uploads/News/" + drvSqlAndrology3["Thumb_Photo"].ToString();
        Image19.Width = 240;
        Image19.Height = 160;
        Image20.ImageUrl = "../Uploads/News/" + drvSqlAndrology4["Thumb_Photo"].ToString();
        Image20.Width = 240;
        Image20.Height = 160;
        HyperLink1.NavigateUrl = "http://62991199.com";
        HyperLink2.NavigateUrl = "http://62991199.com";
        HyperLink3.NavigateUrl = "http://62991199.com";
        HyperLink4.NavigateUrl = "http://62991199.com";
        HyperLink5.NavigateUrl = "http://62991199.com";
        HyperLink6.NavigateUrl = "http://62991199.com";
        HyperLink7.NavigateUrl = "http://62991199.com";
        HyperLink8.NavigateUrl = "http://62991199.com";
        HyperLink9.NavigateUrl = "http://62991199.com";
        HyperLink10.NavigateUrl = "http://62991199.com";*/

        //Image16.ImageUrl="../Uploads/News/" +"<%# DataBinder.Eval(Container.DataItem, "Thumb_Photo")%>";
        if (!Page.IsPostBack)
        {
            string _chuoiKetNoi = @"Data Source=112.78.2.182,1488;uid=nk62991199_user1;pwd=Qwer@1234;Initial Catalog=nk62991199_restore1;connection reset=false;";
            SqlConnection _ketNoi = new SqlConnection(_chuoiKetNoi);
            try
            {
                _ketNoi.Open();
                Response.Write("");//Ket noi thanh cong!
                string _sql = "SELECT  TOP 1000 NCA.[ParentID], NCA.[Name], NCO.[ID],  NCO.[CategoryID], NCO.[Title], NCO.[Thumb_Photo], NCO.[ShortDescription], NCO.[Description] FROM tblNewsCategories NCA INNER JOIN tblNewsContents NCO ON NCO.[CategoryID] = NCA.[ID] WHERE NCA.[ParentID] = 93 ORDER BY NCO.[CategoryID] DESC";
                SqlDataAdapter _adap = new SqlDataAdapter(_sql, _ketNoi);
                DataTable _tb = new DataTable();
                _adap.Fill(_tb);

                // Starting paging here.
                PagedDataSource pds = new PagedDataSource();
                DataView dv = new DataView(_tb);
                pds.DataSource = dv;
                pds.AllowPaging = true;
                // Show number of product in one page.
                pds.PageSize = 6;
                // Specify sum of page.
                int numPage = pds.PageCount;

                int currentPage;
                if (Request.QueryString["page"] != null)
                {
                    currentPage = Int32.Parse(Request.QueryString["page"]);
                }
                else
                {
                    currentPage = 1;
                }
                // Because paging always start at 0.
                pds.CurrentPageIndex = currentPage - 1;
                // Show
                Label1.Text = "Trang " + currentPage + "  trên " + pds.PageCount;
                // Config next - pre link.
                if (!pds.IsFirstPage)
                    lnkPre.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentPage - 1);
                else
                {

                    lnkPre.Visible = false;
                }
                if (!pds.IsLastPage)
                    lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentPage + 1);
                else
                {

                    lnkNext.Visible = false;
                }

                Repeater1.DataSource = pds;
                Repeater1.DataBind();
            }
            catch
            {
                // Print out error here.
                Response.Write("Internet can not access!");
                _ketNoi.Close();
            }
            finally
            {
                _ketNoi.Close();
            }

        }

    }
}
